//
//  HYMeetingInfoCell.m
//  Booking
//
//  Created by Duntech on 2018/4/24.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYMeetingInfoCell.h"
#import "HYMeetingRoomInfoModel.h"

@interface HYMeetingInfoCell ()

@property (nonatomic,strong) UILabel *roomLabel;
@property (nonatomic,strong) UILabel *floorLabel;
@property (nonatomic,strong) UILabel *buildingLabel;
@property (nonatomic,strong) UILabel *cityLabel;
@property (nonatomic,strong) UILabel *telLabel;
@property (nonatomic,strong) UILabel *capacityLabel;
@property (nonatomic,strong) UILabel *deviceLabel;
@property (nonatomic,strong) NSMutableArray *deviceImgViewArray;

@end


@implementation HYMeetingInfoCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.roomLabel];
        [self.contentView addSubview:self.floorLabel];
        [self.contentView addSubview:self.buildingLabel];
        [self.contentView addSubview:self.cityLabel];
        [self.contentView addSubview:self.telLabel];
        [self.contentView addSubview:self.capacityLabel];
        [self.contentView addSubview:self.deviceLabel];

        [self createDeviceImgView];
    }
    return self;
}

- (void)layoutSubviews{
    
    [_roomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(10 * WIDTH_MULTIPLE);
        make.top.equalTo(self).offset(30 * WIDTH_MULTIPLE);
    }];
    
    [_floorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.roomLabel);
        make.top.equalTo(self.roomLabel.mas_bottom).offset(20 * WIDTH_MULTIPLE);
    }];
    
    [_buildingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.roomLabel);
        make.top.equalTo(self.floorLabel.mas_bottom).offset(10 * WIDTH_MULTIPLE);
        
    }];
    
    [_cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.roomLabel);
        make.top.equalTo(self.buildingLabel.mas_bottom).offset(10 * WIDTH_MULTIPLE);
        
    }];
    
    [_telLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.roomLabel);
        make.top.equalTo(self.cityLabel.mas_bottom).offset(10 * WIDTH_MULTIPLE);
    }];
    
    [_capacityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-20 * WIDTH_MULTIPLE);
        make.top.equalTo(self.cityLabel.mas_bottom).offset(10 * WIDTH_MULTIPLE);
    }];
    
    [_deviceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.floorLabel);
        make.right.equalTo(self.capacityLabel);
    }];
}

- (void)createDeviceImgView{
    
    self.deviceImgViewArray = [NSMutableArray array];
    for (NSInteger i = 0; i < 5; i++) {
        
        UIImageView *deviceImgView = [UIImageView new];
        deviceImgView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:deviceImgView];
        deviceImgView.hidden = YES;
        [self.deviceImgViewArray addObject:deviceImgView];
        
        [deviceImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(-i * 30 * WIDTH_MULTIPLE - 20 * WIDTH_MULTIPLE);
            make.top.equalTo(self.deviceLabel);
            make.size.mas_equalTo(CGSizeMake(20 * WIDTH_MULTIPLE, 20 * WIDTH_MULTIPLE));
        }];
    }
}

- (void)configWithModel:(id)model{
    
    HYMeetingRoomInfoModel *cellModel = (HYMeetingRoomInfoModel *)model;
    _roomLabel.text = cellModel.roomName;
    _floorLabel.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"floor", nil),cellModel.floorNo];
    _buildingLabel.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"building", nil),cellModel.buildingName];
    _cityLabel.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"city", nil),cellModel.city];
    _telLabel.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"tel", nil),cellModel.tel];
    _capacityLabel.text = [NSString stringWithFormat:@"%@：%@",NSLocalizedString(@"capacity", nil),cellModel.capacity];
    _deviceLabel.text = cellModel.device;
    _deviceLabel.hidden = YES;
    
    //设备
    NSArray *strArray = [cellModel.device componentsSeparatedByString:@","];
    for (NSInteger i = 0; i < strArray.count; i++) {
        
        UIImageView *deviceImgView = self.deviceImgViewArray[i];
        deviceImgView.hidden = NO;
        if ([strArray[i] isEqualToString:@"投影仪"]) {
            deviceImgView.image = [UIImage imageNamed:@"room-projector-s"];
        }
        if ([strArray[i] isEqualToString:@"电视"]) {
            deviceImgView.image = [UIImage imageNamed:@"room-tv-s"];
        }
        if ([strArray[i] isEqualToString:@"语音设备"]) {
            deviceImgView.image = [UIImage imageNamed:@"room-sound-s"];
        }
        if ([strArray[i] isEqualToString:@"多媒体"]) {
            deviceImgView.image = [UIImage imageNamed:@"room-polycom-s"];
        }
        if ([strArray[i] isEqualToString:@"视频会议"]) {
            deviceImgView.image = [UIImage imageNamed:@"room-vc-s"];
        }
    }
}

#pragma mark - lazyload
- (UILabel *)roomLabel{
    
    if (!_roomLabel) {
        _roomLabel = [UILabel new];
        _roomLabel.textColor = KAPP_BLACK_COLOR;
        _roomLabel.font = KFitBoldFont(18);
    }
    return _roomLabel;
}

- (UILabel *)floorLabel{
    
    if (!_floorLabel) {
        _floorLabel = [UILabel new];
        _floorLabel.textColor = KAPP_THEME_COLOR;
        _floorLabel.font = KFitBoldFont(15);
    }
    return _floorLabel;
}

- (UILabel *)buildingLabel{
    
    if (!_buildingLabel) {
        _buildingLabel = [UILabel new];
        _buildingLabel.textColor = KAPP_THEME_COLOR;
        _buildingLabel.font = KFitBoldFont(15);
    }
    return _buildingLabel;
}

- (UILabel *)cityLabel{
    
    if (!_cityLabel) {
        _cityLabel = [UILabel new];
        _cityLabel.textColor = KAPP_THEME_COLOR;
        _cityLabel.font = KFitBoldFont(15);
    }
    return _cityLabel;
}

- (UILabel *)telLabel{
    
    if (!_telLabel) {
        _telLabel = [UILabel new];
        _telLabel.textColor = KCOLOR(@"848486");
        _telLabel.font = KFitFont(15);
    }
    return _telLabel;
}

- (UILabel *)capacityLabel{
    
    if (!_capacityLabel) {
        _capacityLabel = [UILabel new];
        _capacityLabel.textColor = KCOLOR(@"848486");
        _capacityLabel.font = KFitFont(15);
    }
    return _capacityLabel;
}

- (UILabel *)deviceLabel{
    
    if (!_deviceLabel) {
        _deviceLabel = [UILabel new];
        _deviceLabel.textColor = KAPP_BLACK_COLOR;
        _deviceLabel.font = KFitBoldFont(15);
        _deviceLabel.textAlignment = NSTextAlignmentRight;
    }
    return _deviceLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
